<?php
/**
 * 巡展基金预算
 * @author qianxun
 *
 */
class XunBudget extends MY_Controller{
    function XunBudget(){
        parent::MY_Controller();
        $this->navbarFocus = 'CarBudget';
    }
    /**
     * 专营店列表
     */
    function storeList(){
        if ($this->user['userRole'] != 1){
            showError('您无权限进去此页面');
        }
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('SingleBudget', 'storeList'),'title'=>'巡展基金预算列表');
        
        //载入模型
        $this->load->model('xunProcessModel');
        //年份
        $year = $this->input->get('year');
        $year || $year = $this->config->item('nowYear');
        $this->viewData['year'] = $year;
        //时间单位配置
        $this->viewData['timeUnitList'] = $this->timeUnitModel->getTimeUnitList($year);
        $where = array();
        //专营店ID条件
        $where['storeId'] = array('in', $this->userLib->getViewStoreIds());
        //年份条件
        $where['year'] = $year;
        //巡展基金列表
        $this->viewData['procList'] = $this->xunProcessModel->getNewListByTimeUnit($where);
        $this->load->view('XunBudget/storeList', $this->viewData);
    }
    /**
     * 添加
     */
    function storeAdd(){
        showError('暂无此功能');
    }
    /**
     * 编辑
     */
    function storeEdit(){
        showError('暂无此功能');
    }
    /**
     * 管理端列表
     */
    function adminList(){
        if ($this->user['userRole'] == 1){
            showError('您无权限进去此页面');
        }
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('XunBudget', 'adminList'),'title'=>'巡展基金预算管理');
        //载入模型
        $this->load->model('xunProcessModel');
        $this->load->model('sellpointModel');
        //查询条件
        $where = array();
        //专营店筛选
        $area = $this->input->get('area');
        $this->viewData['area'] = $area;
        $region = $this->input->get('region');
        $this->viewData['region'] = $region;
        $spsarea = $this->input->get('spsarea');
        $this->viewData['spsarea'] = $spsarea;
        $province = $this->input->get('province');
        $this->viewData['province'] = $province;
        $city = $this->input->get('city');
        $this->viewData['city'] = $city;
        $storeId = (int)$this->input->get('storeId');
        $this->viewData['storeId'] = $storeId;
        $keyword = $this->input->get('keyword');
        $this->viewData['keyword'] = $keyword;
        //查找对应地区列表
        $placeStoreList = $this->sellpointModel->searchStore($area, $region, $spsarea, $province, $city, $storeId, $keyword);
        $placeStoreIds = array_keys($placeStoreList);
        $this->viewData['allStoreList'] = $placeStoreList;
        //权限内专营店列表
        $viewStoreIds = $this->userLib->getViewStoreIds();
        if ($viewStoreIds == '*'){
            $where['storeId'] = array('in', $placeStoreIds);
        }else{
            $where['storeId'] = array('in', array_intersect($viewStoreIds, $placeStoreIds));
        }
        //年份
        $year = $this->input->get('year');
        $year || $year = $this->config->item('nowYear');
        $this->viewData['year'] = $year;
        //时间单位
        $this->viewData['timeUnit'] = (int)$this->input->get('timeUnit');
        $this->viewData['timeUnit'] && $where['timeUnit'] = $this->viewData['timeUnit'];
        //年份条件
        $where['year'] = $year;
        //$where['budgetApply > '] =0;
        $count = $this->xunProcessModel->getCount($where);
        //分页
        $this->load->library('pagination');
        $getParam = $_GET;
        unset($getParam['c'], $getParam['m'], $getParam['page']);
        $config['base_url'] = printUrl($_GET['c'], $_GET['m'], $getParam);
        $config['total_rows'] = $count;
        $this->pagination->initialize($config);
        $this->viewData['pager'] = $this->pagination->create_links();
        $page = (int)$this->input->get('page');
        $limit = $this->pagination->per_page;
        
        $this->viewData['procList'] = $this->xunProcessModel->getNewList($where, $limit, $page, '', 'id desc');
        $this->load->view('XunBudget/adminList', $this->viewData);
    }
    /**
     * 预算审核
     */
    function adminAudit(){
        showError('此功能不存在');
    }
    /**
     * 巡展查看
     */
    function check(){
        $procId = (int)$this->input->get('procId');
        $procId || showError('请选择要修改的双月数据');
        $this->viewData['procId'] = $procId;
        //面包屑
        if ($this->user['userRole'] == 1){
            $this->viewData['breadcrumb'][] = array('url'=>$_SERVER['HTTP_REFERER'],'title'=>'巡展基金预算查看');
        }else{
            $this->viewData['breadcrumb'][] = array('url'=>printUrl('XunBudget', 'adminList'),'title'=>'巡展基金预算管理列表');
        }
        $this->viewData['breadcrumb'][] = array('url'=>'','title'=>'预算查看');
        //巡展主线数据
        $this->load->model('xunProcessModel');
        $procData = $this->xunProcessModel->getNewData($procId);
        $this->viewData['procData'] = $procData;
        if (!$this->auth->isXunBudgetCheck($procData)){
            showError('您无权限查看');
        }
        //专营店数据
        $this->load->model('sellpointModel');
        $this->viewData['storeData'] = $this->sellpointModel->getStoreIdData($procData['storeId']);;
        //巡展项目列表
        $this->load->model('xProjectModel');
        $this->viewData['xunProjectList'] = $this->xProjectModel->getNewList(array('procId'=>$procId), NULL, NULL, '', 'createTime desc');
        //查看标记
        $this->viewData['action'] = 'check';
        $this->load->view('XunBudget/check', $this->viewData);
    }
}